<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" th:href="@{/lib/lui/css/layui.css}">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="layui-container">
<div th:html="${courseOnline.id}"></div>
<div th:if="${edit}">
</div>
<form id="courseOnlineForm" class="layui-form" action="edit" method="post">
    <input type="hidden" name="id" th:value="${courseOnline.id}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test1">选择图片</button>
                <div class="layui-upload-list">
                    <img src="/demo/img/7.png" class="layui-upload-img" id="demo1">
                    <p id="demoText"></p>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">科目</label>
        <div th:if="${edit}" class="layui-input-block">
            <input  type="text" name="type" autocomplete="off" th:value="${courseOnline.type}" placeholder="请输入科目" class="layui-input">
        </div>
        <div class="layui-form-mid" th:unless="${edit}" th:text="${courseOnline.type}"></div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div th:if="${edit}" class="layui-input-block">
            <input  type="text" name="title" lay-verify="title" autocomplete="off" th:value="${courseOnline.title}" placeholder="请输入标题" class="layui-input">
        </div>
        <div class="layui-form-mid" th:unless="${edit}" th:text="${courseOnline.title}"></div>
    </div>
    
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">上传时间</label>
            <div th:if="${edit}" class="layui-input-inline">
                <input type="text"  name="createTime" id="date" lay-verify="date" th:value="${#dates.format(courseOnline.createTime, 'yyyy-MM-dd')}"
                       placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid" th:unless="${edit}" th:text="${#dates.format(courseOnline.createTime, 'yyyy-MM-dd')}">
            </div>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">是否热点</label>     
        <div>
            <div>
      			<input type="radio" name="isHotAndCharge" value="0" title="否">
     			<input type="radio" name="isHotAndCharge" value="1" title="热点">
    			<input type="radio" name="isHotAndCharge" value="2" title="收费">
    			<input type="radio" name="isHotAndCharge" value="3" title="热点且收费">
    		</div>
        </div> 
	</div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">是否推荐</label>
        <div th:if="${edit}" class="layui-input-block">
            <div class="layui-input-block">
      			<input type="radio" name="isRecommended" value="true" title="是">
     			<input type="radio" name="isRecommended" value="false" title="否">
    		</div>
        </div> 
        
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">播放次数</label>
        <div th:if="${edit}" class="layui-input-block">
            <input  type="text" name="playNumber" lay-verify="title" autocomplete="off" th:value="${courseOnline.playNumber}" placeholder="" class="layui-input">
        </div>
        <div class="layui-form-mid" th:unless="${edit}" th:text="${courseOnline.playNumber}"></div>
    </div>
    
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div th:if="${edit}" class="layui-input-block">
            <textarea class="layui-textarea" name="content" th:text="${courseOnline.content}">
            </textarea>
        </div>
        <div class="layui-form-mid" th:unless="${edit}" th:text="${courseOnline.content}"></div>
    </div>

</form>
</div>
<script th:src="@{/lib/jquery/jquery.js}"></script>
<script th:src="@{/lib/jquery/jquery.forms.js}"></script>
<script th:src="@{/lib/lui/layui.all.js}"></script>
<script type="text/javascript">	
    $.fn.serializeObject = function()
    {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
</script>
<script type="text/javascript">
    layui.laydate.render({
        elem: '#date'
    });
    //layui.layedit.build('LAY_demo_editor');

    function doSave(fn){

        var data = $("#courseOnlineForm").serializeObject();

        $.ajax("edit",{
            method:"post",
            contentType:"application/json; charset=utf-8",
            data:JSON.stringify(data),
            success:function(data) {
                if(data) {
                    parent.tips(1, "保存成功！");
                    fn.call();
                }else{
                    parent.tips(0, "保存信息失败！");
                }
            },
            error:function(e){
                parent.tips(0,e);
            }
        });

    }
</script>

<script type="text/javascript">
	$(function(){
		var isHotAndCharge = [[${courseOnline.isHotAndCharge}]];
		var isRecommended = [[${courseOnline.isRecommended}]];
		$(function (){
			$("input[type=radio][name=isHotAndCharge]").each(function(){
				var value=$(this).val();
				if(value==isHotAndCharge){
					$(this).next().find("i").click();
				}
			}); 
			
			if(isRecommended==1){
				$("input[type=radio][name=isRecommended]:eq(0)").next().find("i").click();
			}
			else{
				$("input[type=radio][name=isRecommended]:eq(1)").next().find("i").click();
			}
		});
	});
</script>
</body>
</html>